//
//  LRSegmentedControl.m
//  LRSegmentedControl
//
//  Created by liuyanzhi on 14-5-29.
//  Copyright (c) 2014年 karlcool. All rights reserved.
//

#import "LRSegmentedControl.h"

@implementation LRSegmentedControl

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

        UIImage *unselectedBackgroundImage = [[UIImage imageNamed:@"segment-unselected-item.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
        [[UISegmentedControl appearance] setBackgroundImage:unselectedBackgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        UIImage *selectedBackgroundImage = [[UIImage imageNamed:@"segment-selected-item.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
        [[UISegmentedControl appearance] setBackgroundImage:selectedBackgroundImage forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
        UIImage *bothUnselectedImage = [[UIImage imageNamed:@"segment-middle.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 0, 15, 0)];
        [[UISegmentedControl appearance] setDividerImage:bothUnselectedImage forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        UIImage *leftSelectedImage = [[UIImage imageNamed:@"segment-middle.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 0, 15, 0)];
        [[UISegmentedControl appearance] setDividerImage:leftSelectedImage forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        UIImage *rightSelectedImage = [[UIImage imageNamed:@"segment-middle.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 0, 15, 0)];
        [[UISegmentedControl appearance] setDividerImage:rightSelectedImage forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
        
        NSDictionary *selectedAttributes = [NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"Helvetica" size:14.0f], UITextAttributeFont, [UIColor whiteColor], UITextAttributeTextColor, [UIColor clearColor], UITextAttributeTextShadowColor, nil];
        [self setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected];

        NSDictionary *normalAttributes = [NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"Helvetica" size:14.0f], UITextAttributeFont, [UIColor colorWithRed:5.0/255.0 green:167.0/255.0 blue:96.0/255.0 alpha:1], UITextAttributeTextColor, [UIColor clearColor], UITextAttributeTextShadowColor, nil]; [self setTitleTextAttributes:normalAttributes forState:UIControlStateNormal];
        [self setTitleTextAttributes:normalAttributes forState:UIControlStateNormal];
    }
    return self;
}



@end
